If it is a string, you must also give the encoding (and optionally, errors) parameters; bytearray() then converts the string to bytes using str. ... <看更多>
Simply data.encode('utf-8') should be sufficient, if you are converting a string to bytes data. If your string is more than 32 bytes long ... ... <看更多>